home *** CD-ROM | disk | FTP | other *** search
- /**********************************************************************\
-
- File: v meat.c
-
- Purpose: This module handles the options under the Options menu:
- going forward one block, going backward one block, etc.
- These procedures actually change the internal variables
- that tell us what block we're on and then update the
- screen accordingly. Also, changing the fork EOF is
- handled here.
-
-
- Voyeur -- a no-frills file viewer
- Copyright ©1993-4, Mark Pilgrim
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program in a file named "GNU General Public License".
- If not, write to the Free Software Foundation, 675 Mass Ave,
- Cambridge, MA 02139, USA.
-
- \**********************************************************************/
-
- #include "v meat.h"
- #include "program globals.h"
- #include "v hex.h"
- #include "v window maintenance.h"
- #include "v file management.h"
- #include "v error.h"
- #include "v.h"
- #include "msg graphics.h"
- #include "msg dialogs.h"
-
- void ChangeEOF(void)
- {
- DialogPtr theDlog;
- int itemSelected;
- Handle itemH;
- short item,itemType;
- Rect box;
- Str255 tempStr;
- unsigned long temptotal;
- OSErr isHuman;
-
- PositionDialog('DLOG', eofDialog);
- theDlog = GetNewDialog(eofDialog, 0L, (WindowPtr)-1L);
-
- GetDItem(theDlog, 5, &itemType, &itemH, &box);
- InsetRect(&box, -4, -4);
- SetDItem(theDlog, 5, itemType, (Handle)OutlineDefaultButton, &box);
-
- GetDItem(theDlog,4,&itemType,&itemH,&box);
- LongToHexString(gForkLength[gWhichFile][gWhichFork[gWhichFile]], tempStr);
- SetIText(itemH, tempStr);
- SelIText(theDlog, 4, 0, 32767);
- SetWTitle((WindowPtr)theDlog, "\pSet EOF");
-
- ShowWindow(theDlog);
-
- itemSelected=0;
- while ((itemSelected!=1) && (itemSelected!=2))
- {
- ModalDialog((ProcPtr)HexOFilter, &itemSelected);
- }
-
- if (itemSelected==1)
- {
- GetDItem(theDlog,4,&itemType,&itemH,&box);
- GetIText(itemH, tempStr);
- if (tempStr[0]==0x00)
- itemSelected=2;
- }
-
- HideWindow(theDlog);
- DisposeDialog(theDlog);
-
- if (itemSelected==1)
- {
- if (!ValidHex(tempStr))
- HandleError(invalidHexErr);
- else if (tempStr[0]>8)
- HandleError(offsetTooLargeErr);
- else
- {
- temptotal=HexStringToLong(tempStr);
- isHuman=SetEOF(gTheRefNum[gWhichFile], temptotal);
- if (isHuman!=noErr)
- {
- SetEOF(gTheRefNum[gWhichFile], gForkLength[gWhichFile][gWhichFork[gWhichFile]]);
- HandleError(diskFullErr);
- }
- else
- {
- gForkLength[gWhichFile][gWhichFork[gWhichFile]]=temptotal;
- if (gTheOffset[gWhichFile][gWhichFork[gWhichFile]]+gBufferOffset[gWhichFile]>=temptotal)
- {
- if (temptotal%256)
- {
- gTheOffset[gWhichFile][gWhichFork[gWhichFile]]=(temptotal/256)*256;
- gBufferOffset[gWhichFile]=temptotal-gTheOffset[gWhichFile][gWhichFork[gWhichFile]];
- }
- else
- {
- gTheOffset[gWhichFile][gWhichFork[gWhichFile]]=(temptotal==0L) ? 0 : temptotal-256;
- gBufferOffset[gWhichFile]=0;
- }
- }
- GetBuffer(gTheRefNum[gWhichFile], gTheOffset[gWhichFile][gWhichFork[gWhichFile]], gTheBuffer[gWhichFile]);
- UpdateProgramWindow(gWhichFile, TRUE);
- }
- }
- }
- }
-
- void DoDataFork(void)
- {
- int resultCode;
-
- if (gWhichFork[gWhichFile]==1)
- {
- CloseTheFile(gTheRefNum[gWhichFile]);
- gWhichFork[gWhichFile]=0;
- gBufferOffset[gWhichFile]=0;
- resultCode=OpenTheDataFork(&gTheFS[gWhichFile], &gTheRefNum[gWhichFile]);
-
- if (resultCode==allsWell)
- resultCode=GetBuffer(gTheRefNum[gWhichFile], gTheOffset[gWhichFile][gWhichFork[gWhichFile]], gTheBuffer[gWhichFile]);
-
- if (resultCode!=allsWell)
- {
- HandleError(resultCode);
- CloseProgramWindow(gWhichFile);
- }
- else
- UpdateProgramWindow(gWhichFile, TRUE);
- }
- }
-
- void DoResourceFork(void)
- {
- int resultCode;
-
- if (gWhichFork[gWhichFile]==0)
- {
- CloseTheFile(gTheRefNum[gWhichFile]);
- gWhichFork[gWhichFile]=1;
- gBufferOffset[gWhichFile]=0;
- resultCode=OpenTheResourceFork(&gTheFS[gWhichFile], &gTheRefNum[gWhichFile]);
-
- if (resultCode==allsWell)
- resultCode=GetBuffer(gTheRefNum[gWhichFile], gTheOffset[gWhichFile][gWhichFork[gWhichFile]], gTheBuffer[gWhichFile]);
-
- if (resultCode!=allsWell)
- {
- HandleError(resultCode);
- CloseProgramWindow(gWhichFile);
- }
- else
- UpdateProgramWindow(gWhichFile, TRUE);
- }
- }
-
- void GoForward(void)
- {
- int resultCode;
-
- if (gTheOffset[gWhichFile][gWhichFork[gWhichFile]]+256L<gForkLength[gWhichFile][gWhichFork[gWhichFile]])
- {
- gTheOffset[gWhichFile][gWhichFork[gWhichFile]]+=256L;
- gBufferOffset[gWhichFile]=0;
- resultCode=GetBuffer(gTheRefNum[gWhichFile], gTheOffset[gWhichFile][gWhichFork[gWhichFile]], gTheBuffer[gWhichFile]);
- if (resultCode!=allsWell)
- {
- HandleError(resultCode);
- CloseProgramWindow(gWhichFile);
- }
-
- UpdateProgramWindow(gWhichFile, TRUE);
- }
- else SysBeep(7);
- }
-
- void GoBack(void)
- {
- int resultCode;
-
- if (gTheOffset[gWhichFile][gWhichFork[gWhichFile]]>=256L)
- {
- gTheOffset[gWhichFile][gWhichFork[gWhichFile]]-=256L;
- gBufferOffset[gWhichFile]=0;
- resultCode=GetBuffer(gTheRefNum[gWhichFile], gTheOffset[gWhichFile][gWhichFork[gWhichFile]], gTheBuffer[gWhichFile]);
- if (resultCode!=allsWell)
- {
- HandleError(resultCode);
- CloseProgramWindow(gWhichFile);
- }
- else
- UpdateProgramWindow(gWhichFile, TRUE);
- }
- else SysBeep(7);
- }
-
- void GoBeginning(void)
- {
- int resultCode;
-
- if (gTheOffset[gWhichFile][gWhichFork[gWhichFile]]!=0)
- {
- gTheOffset[gWhichFile][gWhichFork[gWhichFile]]=0L;
- gBufferOffset[gWhichFile]=0;
- resultCode=GetBuffer(gTheRefNum[gWhichFile], gTheOffset[gWhichFile][gWhichFork[gWhichFile]], gTheBuffer[gWhichFile]);
- if (resultCode!=allsWell)
- {
- HandleError(resultCode);
- CloseProgramWindow(gWhichFile);
- }
- else
- UpdateProgramWindow(gWhichFile, TRUE);
- }
- }
-
- void GoEnd(void)
- {
- int resultCode;
- unsigned long temp;
-
- if (gForkLength[gWhichFile][gWhichFork[gWhichFile]]%256)
- temp=(gForkLength[gWhichFile][gWhichFork[gWhichFile]]/256)*256;
- else
- temp=gForkLength[gWhichFile][gWhichFork[gWhichFile]]-256;
-
- if (gTheOffset[gWhichFile][gWhichFork[gWhichFile]]!=temp)
- {
- gTheOffset[gWhichFile][gWhichFork[gWhichFile]]=temp;
- gBufferOffset[gWhichFile]=0;
- resultCode=GetBuffer(gTheRefNum[gWhichFile], gTheOffset[gWhichFile][gWhichFork[gWhichFile]], gTheBuffer[gWhichFile]);
- if (resultCode!=allsWell)
- {
- HandleError(resultCode);
- CloseProgramWindow(gWhichFile);
- }
- else
- UpdateProgramWindow(gWhichFile, TRUE);
- }
- }
-
- void GoOffset(void)
- {
- DialogPtr theDlog;
- int itemSelected;
- Handle itemH;
- short item,itemType;
- Rect box;
- Str255 tempStr;
- int i;
- unsigned long tempoff;
-
- PositionDialog('DLOG', offsetDialog);
- theDlog = GetNewDialog(offsetDialog, 0L, (WindowPtr)-1L);
-
- GetDItem(theDlog, 5, &itemType, &itemH, &box);
- InsetRect(&box, -4, -4);
- SetDItem(theDlog, 5, itemType, (Handle)OutlineDefaultButton, &box);
-
- LongToHexString(gTheOffset[gWhichFile][gWhichFork[gWhichFile]], tempStr);
- GetDItem(theDlog,4,&itemType,&itemH,&box);
- SetIText(itemH, tempStr);
- SelIText(theDlog, 4, 0, 32767);
- SetWTitle((WindowPtr)theDlog, "\pGo to offset");
-
- ShowWindow(theDlog);
-
- itemSelected=0;
- while ((itemSelected!=1) && (itemSelected!=2))
- {
- ModalDialog((ProcPtr)HexOFilter, &itemSelected);
- }
-
- if (itemSelected==1)
- {
- GetDItem(theDlog,4,&itemType,&itemH,&box);
- GetIText(itemH, tempStr);
- if (tempStr[0]==0x00)
- itemSelected=2;
- }
-
- HideWindow(theDlog);
- DisposeDialog(theDlog);
-
- if (itemSelected==1)
- {
- if (!ValidHex(tempStr))
- HandleError(invalidHexErr);
- else if (tempStr[0]>8)
- HandleError(offsetTooLargeErr);
- else
- {
- tempoff=HexStringToLong(tempStr);
- if (tempoff>=gForkLength[gWhichFile][gWhichFork[gWhichFile]])
- HandleError(offsetTooLargeErr);
- else
- {
- if (tempoff%256)
- {
- gTheOffset[gWhichFile][gWhichFork[gWhichFile]]=(tempoff/256)*256;
- gBufferOffset[gWhichFile]=tempoff-gTheOffset[gWhichFile][gWhichFork[gWhichFile]];
- }
- else
- {
- gTheOffset[gWhichFile][gWhichFork[gWhichFile]]=tempoff;
- gBufferOffset[gWhichFile]=0;
- }
- GetBuffer(gTheRefNum[gWhichFile], gTheOffset[gWhichFile][gWhichFork[gWhichFile]], gTheBuffer[gWhichFile]);
- UpdateProgramWindow(gWhichFile, TRUE);
- }
- }
- }
- }
-